package com.lineng.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.alibaba.fastjson.JSON;
import com.lineng.pojo.Home;
import com.lineng.service.HomeService;

@Controller
public class HomeController {
	@Autowired
	HomeService homeService;

	/**
	 * 获取首页内容
	 * 
	 * @return
	 */
	@RequestMapping(value = "/getHome", method = RequestMethod.GET, produces = "text/json;charset=UTF-8")
	@ResponseBody
	public String getHome() {
		List<Home> homes = homeService.getHome();
		return JSON.toJSONString(homes);

	}

	/**
	 * 更改首页内容
	 * 
	 * @param home
	 * @param file
	 * @return
	 */
	@RequestMapping(value = "/updateHome", method = RequestMethod.POST, produces = "text/json;charset=UTF-8")
	@ResponseBody
	public String updateHome(Home home, MultipartFile file) {
		return JSON.toJSONString(homeService.updateHome(home, file));

	}

}
